local qingdin = fk.CreateSkill{
  name = "hanqing__qingdin",
  dynamic_desc = function (self, player, lang)
    if player:getMark(self.name) == 1 then
      return "hanqing__qingdin_update1"
    elseif player:getMark(self.name) == 2 then
      return "hanqing__qingdin_update2"
    end
  end,
}

Fk:loadTranslationTable{
  ["hanqing__qingdin"] = "擎鼎",
  [":hanqing__qingdin"] = "连续两张牌面描述带【杀】的牌被使用后，你可以使用一张牌面描述带【杀】的牌，若均为伤害牌/【杀】，"..
  "摸三张牌并将〖擎鼎〗的“牌面描述带【杀】”替换为伤害牌/【杀】。",

  [":hanqing__qingdin_update1"] = "连续两张伤害牌被使用后，你可以使用一张伤害牌，摸三张牌，若均为【杀】，将〖擎鼎〗的“伤害牌”替换为【杀】。",
  [":hanqing__qingdin_update2"] = "连续两张【杀】被使用后，你可以使用一张【杀】，摸三张牌。",

  ["#hanqing__qingdin0-use"] = "擎鼎：你可以使用一张牌面描述带【杀】的牌（前两张牌：【%arg】、【%arg2】）",
  ["#hanqing__qingdin1-use"] = "擎鼎：你可以使用一张伤害牌（前两张牌：【%arg】、【%arg2】）",
  ["#hanqing__qingdin2-use"] = "擎鼎：你可以使用一张【杀】（前两张牌：【%arg】、【%arg2】）",
}

qingdin:addEffect(fk.CardUseFinished, {
  anim_type = "offensive",
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(qingdin.name) then
      local room = player.room
      local last
      if #room.logic:getEventsByRule(GameEvent.UseCard, 2, function (e)
        last = e.data.card
        return true
      end, 0) < 2 then return end
      event:setCostData(self, {extra_data = last})
      if player:getMark(qingdin.name) == 0 then
        return table.contains(room:getBanner(qingdin.name)[1], data.card.name) and
          table.contains(room:getBanner(qingdin.name)[1], last.name)
      elseif player:getMark(qingdin.name) == 1 then
        return data.card.is_damage_card and last.is_damage_card
      elseif player:getMark(qingdin.name) == 2 then
        return data.card.trueName == "slash" and last.trueName == "slash"
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local pattern = "slash"
    local last = event:getCostData(self).extra_data
    if player:getMark(qingdin.name) == 0 then
      pattern = ".|.|.|.|"..table.concat(room:getBanner(qingdin.name)[1], ";")
    elseif player:getMark(qingdin.name) == 1 then
      pattern = ".|.|.|.|"..table.concat(room:getBanner(qingdin.name)[2], ";")
    end
    local use = room:askToPlayCard(player, {
      skill_name = qingdin.name,
      pattern = pattern,
      prompt = "#hanqing__qingdin"..player:getMark(qingdin.name).."-use:::"..last.name..":"..data.card.name,
      cancelable = true,
      extra_data = {
        bypass_times = true,
        extraUse = true,
      },
      skip = true,
    })
    if player.dead then return end
    local yes = false
    local level = player:getMark(qingdin.name)
    if use then
      if last.trueName == "slash" and data.card.trueName == "slash" and use.card.trueName == "slash" then
        yes = true
        level = 2
      elseif last.is_damage_card and data.card.is_damage_card and use.card.is_damage_card then
        yes = true
        level = 1
      end
      room:useCard(use)
    elseif player:hasSkill("hanqing__aokua") and target.kingdom == "qin" then
      player:broadcastSkillInvoke("hanqing__aokua")
      room:notifySkillInvoked(player, "hanqing__aokua", "negative")
      room:setPlayerMark(player, qingdin.name, 0)
      room:loseHp(player, 1, qingdin.name)
      return
    end
    if player.dead then return end
    if yes then
      if player:hasSkill(qingdin.name, true) and player:getMark(qingdin.name) < level then
        room:setPlayerMark(player, qingdin.name, level)
      end
      player:drawCards(3, qingdin.name)
    end
  end,
})

qingdin:addAcquireEffect(function (self, player, is_start)
  local room = player.room
  if not room:getBanner(qingdin.name) then
    local names1, names2 = {}, {}
    for name, c in pairs(Fk.all_card_types) do
      if c.trueName == "slash" or string.find(Fk:translate(":"..name, "zh_CN"), "【杀】") then
        table.insert(names1, name)
      end
      if c.is_damage_card then
        table.insert(names2, name)
      end
    end
    room:setBanner(qingdin.name, {names1, names2})
  end
end)

qingdin:addLoseEffect(function (self, player, is_death)
  player.room:setPlayerMark(player, qingdin.name, 0)
end)

return qingdin
